<?php
class MY_Controller extends CI_Controller {	
	function __construct() {		
		parent::__construct();
		$this->load->model('Users_m','users');
		$this->load->model('Register_m','register');
		if(!$this->session->userdata('tinh_thanh')){			
			$this->session->set_userdata('tinh_thanh', $this->register->get_tinh_thanh());
		}
		if(!$this->session->userdata('dich_vu')){
			$dichvu	= array();
			$this->load->model('dichvu_m', 'dichvu');
			foreach($this->dichvu->get_dichvu() as $obj)
				$dichvu[$obj->id] = $obj->ten;
			$this->session->set_userdata('dich_vu', $dichvu);
		}
		$this->load->model('Page_m', 'page');
		$this->pages = $this->page->get_pages();		
		// echo '<pre>';print_r($this->pages);die;		
		if(!$this->session->userdata('options')){
			$this->load->model('option_m', 'option');
			$options	=	$this->option->get_options();
			$this->session->set_userdata('options', $options);
		}
		$options = $this->session->userdata('options');
		foreach($options as $obj)
			$this->config->set_item($obj->key, $obj->value);
		// echo '<pre>';print_r($this->config);die;
		//
		global $userdata, $statistic_users, $point;
		$userdata = $this->session->userdata('userdata');
		//				
		$this->load->library('OnlineUsers');
		$statistic_users	=	$this->onlineusers->get_statistic();
		//
		if($this->users->is_logged_in()){
			$this->load->model('tuyendung_m', 'tuyendung');
			$point	=	$this->tuyendung->get_point();		
			if($point) $point = $point->so_diem;
			else $point = 0;
		}
		date_default_timezone_set('Asia/Bangkok');		
	}
	
	function check_captcha($input){
		$captcha = $this->session->userdata('captcha');
		if(strtoupper($input) != strtoupper($captcha)){
			$this->form_validation->set_message('check_captcha', "<strong>Mã bảo mật</strong> nhập không đúng.");
			$this->session->unset_userdata('captcha');
			return false;
		}
		$this->session->unset_userdata('captcha');
		return true;
	}
}